package com.zetor.ms.application.adapter.impl;

import com.zetor.ms.application.adapter.ISeataAdapter;
import com.zetor.ms.application.feign.client.SeataBClient;
import com.zetor.ms.application.feign.client.SeataCClient;
import com.zetor.ms.core.bo.Result;
import com.zetor.ms.core.util.HisResultUtil;
import com.zetor.ms.core.util.LogUtils;
import com.zetor.ms.facade.vo.DemoParamVO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * TODO
 *
 * @Author zlc
 * @Date 2021/12/20
 */
@Component
public class SeataAdapterImpl implements ISeataAdapter {
    @Resource
    private SeataBClient bClient;

    @Resource
    private SeataCClient stockClient;

    @Resource
    private SeataBClient demoOrderClient;

    @Override
    public Long seataBCase1() {
        Result<Long> res = bClient
                .seataCase1();
        if (HisResultUtil.isSuccess(res) && HisResultUtil.hasBody(res)) {
            return res.getBody();
        }
        LogUtils.error(res.getHead().getMessage());
        return 0L;
    }

    @Override
    public Long seataBCase2() {
        Result<Long> res = bClient
                .seataCase2();
        if (HisResultUtil.isSuccess(res) && HisResultUtil.hasBody(res)) {
            return res.getBody();
        }
        LogUtils.error(res.getHead().getMessage());
        return 0L;
    }

    @Override
    public Long seataSpdCase3() {
        Result<Long> res = demoOrderClient
                .seataCase3();
        if (HisResultUtil.isSuccess(res) && HisResultUtil.hasBody(res)) {
            return res.getBody();
        }
        LogUtils.error(res.getHead().getMessage());
        return 0L;
    }

    @Override
    public Long seataCCase4(Long orderId) {
        DemoParamVO param = new DemoParamVO();
        param.setId(String.valueOf(orderId));
        Result<Long> res = stockClient
                .seataCase4(param);
        if (HisResultUtil.isSuccess(res) && HisResultUtil.hasBody(res)) {
            return res.getBody();
        }
        LogUtils.error(res.getHead().getMessage());
        return 0L;
    }



}
